/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views;

import Common.ConnectionDB;
import Common.Constant;
import DAO.*;
import Helper.*;
import Model.*;
import java.awt.Point;
import java.awt.event.*;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author KIENLT
 */
public class Bills extends javax.swing.JDialog {

    ArrayList<ItemHelper> arrItem;
    ArrayList<ItemHelper> arrItemList;
    ArrayList<BillsHepler> arrBill;
    ArrayList<BillsHepler> arrBillList;
    ArrayList<BillsHepler> arrBills;
    ArrayList<BillsHepler> arrBillsList;
    ArrayList arrList = new ArrayList();
    ItemHelper itemData;
    BillsHepler billData;
    BillsHepler billsData;
    CategoryHelper cateData;
    ResultSet rs = null;
    private String Id = "";
    private String CateId = "";
    private String CusId;
    private String CusName;
    private String UserId;
    int iRow;
    private String ItemId;
    Vector vtUpdate;
    Vector vtCurrentBills;
    JPopupMenu popmenu2;

    /**
     * Creates new form Items
     */
    public Bills(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Constant.initBundle();
        popmenu2 = new JPopupMenu();
        loadLanguage();
        loadTree();
        loadItems();
        buildPopupMenu();
    }

    public void loadCustomer(String id, String name) {
        setCusId(id);
        txtCustomer.setText(name);
    }

    public void reload() {
        try {
            txtId.setText("");
            txtName.setText("");
            txtQuantity.setText("");
            arrList = new ArrayList();
            loadBills(arrList);
            loadItems();
        } catch (Exception ex) {
            Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void buildPopupMenu() {
        JMenuItem menu1 = new JMenuItem("Report out of stock");
        menu1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    //lay du dong
                    rs = ItemDAO.FindOne(ConnectionDB.ConnectionDatabase(), itemData);
                    if (rs.next()) {
                        itemData.setStatus(rs.getString("Status"));
                        int query = ItemDAO.UpdateStatus(ConnectionDB.ConnectionDatabase(), itemData);
                        if (query > 0) {
                            JOptionPane.showMessageDialog(Bills.this, "Send report successfully.", "Message", JOptionPane.INFORMATION_MESSAGE);
                            loadItems();
                        } else {
                            JOptionPane.showMessageDialog(Bills.this, "Send report error.", "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } catch (Exception ex) {
                    Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        popmenu1.add(menu1);

        JMenuItem menu2 = new JMenuItem("Delete");
        menu2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    ItemModel model = (ItemModel)tblBills.getModel();
                    for(int i=0; i<arrList.size(); i++){
                        setItemId(tblBills.getModel().getValueAt(iRow, 0).toString());
                        if(((BillsDetailHelper)arrList.get(i)).getId().equals(getItemId())){
                            arrList.remove(i);
                            model.deleteRow(iRow);
                            return;
                        }
                    }
                } catch (Exception ex) {
                    Logger.getLogger(BillsDetail.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        popmenu2.add(menu2);
    }

    private void loadBills(ArrayList arr) throws Exception {
        arrItem = ItemDAO.FindOne(ConnectionDB.ConnectionDatabase(), arr);
        arrItemList = new ArrayList<ItemHelper>();

        for (ItemHelper item : arrItem) {
            arrItemList.add(item);
        }

        tblBills.setModel(new ItemModel(arrItemList));

        DefaultTableColumnModel model = (DefaultTableColumnModel) tblBills.getColumnModel();
        TableColumn tblCol = model.getColumn(0);
        tblCol.setPreferredWidth(10);
    }

    private void loadLanguage() {
        lblId.setText(Constant.getBundle().getString("id"));
        lblName.setText(Constant.getBundle().getString("iname"));
        lblSName.setText(Constant.getBundle().getString("iname"));
        lblQuantity.setText(Constant.getBundle().getString("quantity"));
        btnAdd.setText(Constant.getBundle().getString("add"));
        lblCusName.setText(Constant.getBundle().getString("cusname"));
        btnCreate.setText(Constant.getBundle().getString("create"));

        lblBillsId.setText(Constant.getBundle().getString("billsid"));
        lblCusname.setText(Constant.getBundle().getString("cusname"));
        lblUsername.setText(Constant.getBundle().getString("username"));
        btnCreateOrder.setText(Constant.getBundle().getString("createorder"));
        btnDeleteBills.setText(Constant.getBundle().getString("cancelbills"));
        lblTotal.setText(Constant.getBundle().getString("total"));
    }

    private void loadItems() {
        try {
            arrItem = ItemDAO.FindAll(ConnectionDB.ConnectionDatabase());
            arrItemList = new ArrayList<ItemHelper>();

            for (ItemHelper item : arrItem) {
                arrItemList.add(item);
            }

            tblItems.setModel(new ItemModel(arrItemList));

            DefaultTableColumnModel model = (DefaultTableColumnModel) tblItems.getColumnModel();
            TableColumn tblCol = model.getColumn(0);
            tblCol.setPreferredWidth(10);
        } catch (Exception ex) {
            try {
                ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
            } catch (Exception ex1) {
                Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }

        tblItems.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {

                    @Override
                    public void valueChanged(ListSelectionEvent e) {

                        boolean adjust = e.getValueIsAdjusting();
                        if (adjust) {
                            FindOne();
                        }
                    }
                });
    }

    private void loadTree() {
        try {
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("Supplier/Category");

            rs = SuppliersDAO.FillAll(ConnectionDB.ConnectionDatabase());
            while (rs.next()) {
                DefaultMutableTreeNode node = new DefaultMutableTreeNode(new SuppliersHepler(rs.getString("SID"), rs.getString("SName")));
                CategoryHelper c = new CategoryHelper();
                c.setSupplierId(rs.getString("SID"));
                ResultSet rsCat = CategoryDAO.FillAll(ConnectionDB.ConnectionDatabase(), c);
                while (rsCat.next()) {
                    node.add(new DefaultMutableTreeNode(new CategoryHelper(rsCat.getString("CatID"), rsCat.getString("CatName"))));
                }
                root.add(node);
            }
            DefaultTreeModel treeModel = new DefaultTreeModel(root);
            treeCategory.setModel(treeModel);
            treeCategory.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

                @Override
                public void valueChanged(TreeSelectionEvent e) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
                    if (node == null) {
                        return;
                    }
                    Object info = node.getUserObject();
                    if (node.isRoot()) {
                        SuppliersHepler s = (SuppliersHepler) info;
                    }
                    if (node.isLeaf()) {
                        CategoryHelper t = (CategoryHelper) info;
                        setCateId(t.getId());
                        FindByCategory(t);
                    }
                }
            });
        } catch (Exception ex) {
            Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void FindByCategory(CategoryHelper obj) {
        try {
            arrItem = ItemDAO.FindByCategory(ConnectionDB.ConnectionDatabase(), obj);
            arrItemList = new ArrayList<ItemHelper>();

            for (ItemHelper item : arrItem) {
                arrItemList.add(item);
            }

            tblItems.setModel(new ItemModel(arrItemList));

            DefaultTableColumnModel model = (DefaultTableColumnModel) tblItems.getColumnModel();
            TableColumn tblCol = model.getColumn(0);
            tblCol.setPreferredWidth(10);
        } catch (Exception ex) {
            try {
                ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
            } catch (Exception ex1) {
                Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }

        tblItems.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {

                    @Override
                    public void valueChanged(ListSelectionEvent e) {

                        boolean adjust = e.getValueIsAdjusting();
                        if (adjust) {
                            FindOne();
                        }
                    }
                });
    }

    private void FindOne() {
        try {
            itemData = new ItemHelper();
            int row = tblItems.getSelectedRow();
            itemData.setId(tblItems.getValueAt(row, 0).toString());
            rs = ItemDAO.FindOne(ConnectionDB.ConnectionDatabase(), itemData);
            if (rs.next()) {
                txtId.setText(rs.getString("IID"));
                txtName.setText(rs.getString("IName"));
            }
        } catch (Exception ex) {
        }
    }

    private void loadBillsDetail() {
        try {
            arrBill = BillsDAO.FindAll(ConnectionDB.ConnectionDatabase());
            arrBillList = new ArrayList<BillsHepler>();

            for (BillsHepler item : arrBill) {
                arrBillList.add(item);
            }

            tblBillsDetail.setModel(new BillsDetailModel(arrBillList));

            DefaultTableColumnModel model = (DefaultTableColumnModel) tblBillsDetail.getColumnModel();
            TableColumn tblCol = model.getColumn(0);
            tblCol.setPreferredWidth(10);
        } catch (Exception ex) {
            try {
                ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
            } catch (Exception ex1) {
            }
        }

        tblBillsDetail.getSelectionModel().addListSelectionListener(
                new ListSelectionListener() {

                    @Override
                    public void valueChanged(ListSelectionEvent e) {

                        boolean adjust = e.getValueIsAdjusting();
                        if (adjust) {
                            FillOneBills();
                        }
                    }
                });
    }

    private void FillOneBills() {
        try {
            billData = new BillsHepler();
            int row = tblBillsDetail.getSelectedRow();
            billData.setId(tblBillsDetail.getValueAt(row, 0).toString());
            rs = BillsDAO.FindOne(ConnectionDB.ConnectionDatabase(), billData);
            if (rs.next()) {
                txtListId.setText(rs.getString("BID"));
                txtListCusname.setText(rs.getString("CName"));
                txtUsername.setText(rs.getString("Username"));
            }
            loadItemBills(billData.getId());
        } catch (Exception ex) {
        }
    }

    private void loadItemBills(String id) {
        try {
            billsData = new BillsHepler();
            billsData.setId(id);
            arrBills = BillsDAO.FindItemBills(ConnectionDB.ConnectionDatabase(), billsData);
            arrBillsList = new ArrayList<BillsHepler>();

            for (BillsHepler item : arrBills) {
                arrBillsList.add(item);
            }

            tblBillsItems.setModel(new BillsModel(arrBillsList));
            int total = 0;
            for (int i = 0; i < arrBillsList.size(); i++) {
                total += Integer.parseInt(((BillsHepler) arrBillsList.get(i)).getTotal());
            }
            lblTotalNumber.setText(String.valueOf(total));
            DefaultTableColumnModel model = (DefaultTableColumnModel) tblBillsItems.getColumnModel();
            TableColumn tblCol = model.getColumn(0);
            tblCol.setPreferredWidth(10);
        } catch (Exception ex) {
            try {
                ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
            } catch (Exception ex1) {
            }
            ex.printStackTrace();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popmenu1 = new javax.swing.JPopupMenu();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblItems = new javax.swing.JTable();
        txtSName = new javax.swing.JTextField();
        lblSName = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        lblId = new javax.swing.JLabel();
        lblName = new javax.swing.JLabel();
        lblQuantity = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        txtName = new javax.swing.JTextField();
        txtQuantity = new javax.swing.JTextField();
        btnAdd = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblBills = new javax.swing.JTable();
        btnCreate = new javax.swing.JButton();
        lblCusName = new javax.swing.JLabel();
        txtCustomer = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        treeCategory = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        lblBillsId = new javax.swing.JLabel();
        txtListId = new javax.swing.JTextField();
        lblCusname = new javax.swing.JLabel();
        txtListCusname = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tblBillsItems = new javax.swing.JTable();
        lblTotal = new javax.swing.JLabel();
        lblTotalNumber = new javax.swing.JLabel();
        btnCreateOrder = new javax.swing.JButton();
        btnDeleteBills = new javax.swing.JButton();
        lblUsername = new javax.swing.JLabel();
        txtUsername = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tblBillsDetail = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblItems.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblItems.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblItemsMouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tblItems);

        txtSName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSNameKeyReleased(evt);
            }
        });

        lblSName.setText("Name");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(lblSName)
                        .addGap(18, 18, 18)
                        .addComponent(txtSName, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblId.setText("ID");

        lblName.setText("Name");

        lblQuantity.setText("Quantity");

        txtId.setEditable(false);

        txtName.setEditable(false);

        btnAdd.setText("jButton1");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        tblBills.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblBills.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tblBillsMouseReleased(evt);
            }
        });
        jScrollPane3.setViewportView(tblBills);

        btnCreate.setText("jButton1");
        btnCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateActionPerformed(evt);
            }
        });

        lblCusName.setText("Cus");

        txtCustomer.setEditable(false);
        txtCustomer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtCustomerMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnCreate)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(lblCusName)
                                .addGap(18, 18, 18)
                                .addComponent(txtCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(lblId)
                                .addGap(18, 18, 18)
                                .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblName)
                                .addGap(18, 18, 18)
                                .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblQuantity)
                                .addGap(18, 18, 18)
                                .addComponent(txtQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnAdd)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblId)
                    .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblName)
                    .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblQuantity)
                    .addComponent(txtQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAdd))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCusName)
                    .addComponent(txtCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCreate))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        treeCategory.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        treeCategory.setAutoscrolls(true);
        jScrollPane2.setViewportView(treeCategory);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Create Bills", jPanel1);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblBillsId.setText("id");

        txtListId.setEditable(false);

        lblCusname.setText("customer name");

        txtListCusname.setEditable(false);

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Items"));

        tblBillsItems.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane6.setViewportView(tblBillsItems);

        lblTotal.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblTotal.setText("Total");

        lblTotalNumber.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lblTotal)
                        .addGap(38, 38, 38)
                        .addComponent(lblTotalNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(lblTotal))
                    .addComponent(lblTotalNumber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        btnCreateOrder.setText("jButton1");
        btnCreateOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateOrderActionPerformed(evt);
            }
        });

        btnDeleteBills.setText("jButton2");
        btnDeleteBills.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteBillsActionPerformed(evt);
            }
        });

        lblUsername.setText("customer name");

        txtUsername.setEditable(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(lblBillsId)
                        .addGap(18, 18, 18)
                        .addComponent(txtListId, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(58, 58, 58)
                        .addComponent(lblCusname)
                        .addGap(18, 18, 18)
                        .addComponent(txtListCusname)
                        .addGap(18, 18, 18)
                        .addComponent(lblUsername)
                        .addGap(18, 18, 18)
                        .addComponent(txtUsername)
                        .addGap(77, 77, 77))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(btnCreateOrder)
                        .addGap(18, 18, 18)
                        .addComponent(btnDeleteBills)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblBillsId)
                    .addComponent(txtListId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCusname)
                    .addComponent(txtListCusname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUsername)
                    .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCreateOrder)
                    .addComponent(btnDeleteBills))
                .addContainerGap())
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblBillsDetail.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane5.setViewportView(tblBillsDetail);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 750, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("List Bills", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 807, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Bills");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        try {
            // TODO add your handling code here:
            if (checkForm()) {
                try {
                    boolean flag = false;
                    rs = ItemDAO.FindQuantity(ConnectionDB.ConnectionDatabase(), txtId.getText());
                    if (rs.next()) {
                        int result = Integer.parseInt(rs.getString("QuantityAvailable")) - Integer.parseInt(txtQuantity.getText());
                        if (result < 0) {
                            JOptionPane.showMessageDialog(this, "Quantity not enough.", "Wanning", JOptionPane.WARNING_MESSAGE);
                            txtQuantity.setText("");
                            return;
                        }
                    }
                    if (arrList.isEmpty()) {
                        arrList.add(new BillsDetailHelper(txtId.getText(), txtQuantity.getText()));
                    } else {
                        for (int i = 0; i < arrList.size(); i++) {
                            if (!((BillsDetailHelper) arrList.get(i)).getId().equals(txtId.getText())) {
                                flag = true;
                            } else {
                                arrList.remove(i);
                                arrList.add(new BillsDetailHelper(txtId.getText(), txtQuantity.getText()));
                                flag = false;
                                break;
                            }
                        }
                        if (flag) {
                            arrList.add(new BillsDetailHelper(txtId.getText(), txtQuantity.getText()));
                        }
                    }
                    loadBills(arrList);
                } catch (Exception ex) {
                    try {
                        ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
                    } catch (Exception ex1) {
                        Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex1);
                    }
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnAddActionPerformed

    private void txtSNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSNameKeyReleased
        // TODO add your handling code here:
        try {
            itemData = new ItemHelper();
            itemData.setName(txtSName.getText());
            itemData.setCategoryId(getCateId());
            arrItem = ItemDAO.Search(ConnectionDB.ConnectionDatabase(), itemData);
            arrItemList = new ArrayList<ItemHelper>();

            for (ItemHelper item : arrItem) {
                arrItemList.add(item);
            }

            tblItems.setModel(new ItemModel(arrItemList));

            DefaultTableColumnModel model = (DefaultTableColumnModel) tblItems.getColumnModel();
            TableColumn tblCol = model.getColumn(0);
            tblCol.setPreferredWidth(10);
        } catch (Exception ex) {
            try {
                ConnectionDB.CloseDB(ConnectionDB.ConnectionDatabase());
            } catch (Exception ex1) {
                Logger.getLogger(Users.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
    }//GEN-LAST:event_txtSNameKeyReleased

    private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateActionPerformed
        try {
            // TODO add your handling code here:
            boolean flag = false;
            if (!txtCustomer.getText().equals("")) {
                BillsHepler bills = new BillsHepler();
                bills.setUserId(getUserId());
                bills.setCusId(getCusId());
                if (!getId().equals("")) {
                    BillsDAO.DeleteBillsDetail(ConnectionDB.ConnectionDatabase(), getId());
                    BillsDAO.DeleteBills(ConnectionDB.ConnectionDatabase(), getId());
                    BillsDAO.InsertBills(ConnectionDB.ConnectionDatabase(), bills);
                } else {
                    BillsDAO.InsertBills(ConnectionDB.ConnectionDatabase(), bills);
                }
                rs = BillsDAO.FindOne(ConnectionDB.ConnectionDatabase());
                if (rs.next()) {
                    for (int i = 0; i < arrList.size(); i++) {
                        ItemHelper item = new ItemHelper();
                        item.setId(((BillsDetailHelper) arrList.get(i)).getId());
                        ResultSet rs1 = ItemDAO.FindOne(ConnectionDB.ConnectionDatabase(), item);
                        if (rs1.next()) {
                            setId(rs1.getString("IID"));
                            bills.setItemId(rs1.getString("IID"));
                            bills.setId(rs.getString("BID"));
                            bills.setQuantity(((BillsDetailHelper) arrList.get(i)).getQuantiry());
                            bills.setPrice(rs1.getString("Price"));
                            int query = BillsDAO.InsertBillsDetail(ConnectionDB.ConnectionDatabase(), bills);
                            if (query > 0) {
                                flag = true;
                            } else {
                                flag = false;
                            }
                        }
                    }
                    if (flag) {
                        BillsDetail bd = new BillsDetail(this, false, rs.getString("BID"));
                        bd.setVisible(true);
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Bills not found.", "Wanning", JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(this, "Customer Name is not empty.", "Wanning", JOptionPane.WARNING_MESSAGE);
            }
        } catch (Exception ex) {
            Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnCreateActionPerformed

    private void tblItemsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblItemsMouseReleased
        // TODO add your handling code here:
        if (evt.getButton() == MouseEvent.BUTTON3) {
            try {
                Point p = new Point(evt.getXOnScreen(), evt.getYOnScreen());
                popmenu1.setLocation(p);
                popmenu1.setVisible(true);
                //
                Point p1 = new Point(evt.getX(), evt.getY());
                //            int col = tblItems.columnAtPoint(p1);
                int row = tblItems.rowAtPoint(p1);
                itemData = new ItemHelper();
                String id = tblItems.getValueAt(row, 0).toString();
                itemData.setId(id);
            } catch (Exception ex) {
                Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_tblItemsMouseReleased

    private void txtCustomerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtCustomerMouseClicked
        // TODO add your handling code here:
        CustomerPopup cp = new CustomerPopup(this, true);
        cp.setVisible(true);
    }//GEN-LAST:event_txtCustomerMouseClicked

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
        // TODO add your handling code here:
        int iSelected = jTabbedPane1.getSelectedIndex();
        if (iSelected == 1) {
            loadBillsDetail();
        }
    }//GEN-LAST:event_jTabbedPane1StateChanged

    private void btnCreateOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateOrderActionPerformed
        try {
            // TODO add your handling code here:
            billsData = new BillsHepler();
            billsData.setId(txtListId.getText());
            int query = BillsDAO.UpdateBillsStatus(ConnectionDB.ConnectionDatabase(), billsData);
            if (query > 0) {
                JOptionPane.showMessageDialog(this, "Create Order Success.", "Message", JOptionPane.INFORMATION_MESSAGE);
                loadBillsDetail();
            } else {
                JOptionPane.showMessageDialog(this, "Create Order Error.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
        }
    }//GEN-LAST:event_btnCreateOrderActionPerformed

    private void btnDeleteBillsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteBillsActionPerformed
        try {
            // TODO add your handling code here:
            int query = BillsDAO.DeleteBills(ConnectionDB.ConnectionDatabase(), txtListId.getText());
            if (query > 0) {
                JOptionPane.showMessageDialog(this, "Delete Bills Success.", "Message", JOptionPane.INFORMATION_MESSAGE);
                loadBillsDetail();
            } else {
                JOptionPane.showMessageDialog(this, "Delete Bills Error.", "Error", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnDeleteBillsActionPerformed

    private void tblBillsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBillsMouseReleased
        // TODO add your handling code here:
        if (evt.getButton() == MouseEvent.BUTTON3) {
            try {
                Point p = new Point(evt.getXOnScreen(), evt.getYOnScreen());
                popmenu2.setLocation(p);
                popmenu2.setVisible(true);
                iRow = tblBills.rowAtPoint(new Point(evt.getX(), evt.getY()));
            } catch (Exception ex) {
                Logger.getLogger(Bills.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_tblBillsMouseReleased

    private boolean checkForm() {
        if (txtName.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Name is not empty.", "Wanning", JOptionPane.WARNING_MESSAGE);
            txtName.requestFocus();
            return false;
        }
        if (txtQuantity.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Quantity is not empty.", "Wanning", JOptionPane.WARNING_MESSAGE);
            txtQuantity.requestFocus();
            return false;
        }
        return true;
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /*
//         * Set the Nimbus look and feel
//         */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /*
//         * If Nimbus (introduced in Java SE 6) is not available, stay with the
//         * default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(Items.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(Items.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(Items.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(Items.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
//        /*
//         * Create and display the dialog
//         */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                Items dialog = new Items(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//
//                    @Override
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCreate;
    private javax.swing.JButton btnCreateOrder;
    private javax.swing.JButton btnDeleteBills;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lblBillsId;
    private javax.swing.JLabel lblCusName;
    private javax.swing.JLabel lblCusname;
    private javax.swing.JLabel lblId;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblQuantity;
    private javax.swing.JLabel lblSName;
    private javax.swing.JLabel lblTotal;
    private javax.swing.JLabel lblTotalNumber;
    private javax.swing.JLabel lblUsername;
    private javax.swing.JPopupMenu popmenu1;
    private javax.swing.JTable tblBills;
    private javax.swing.JTable tblBillsDetail;
    private javax.swing.JTable tblBillsItems;
    private javax.swing.JTable tblItems;
    private javax.swing.JTree treeCategory;
    private javax.swing.JTextField txtCustomer;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtListCusname;
    private javax.swing.JTextField txtListId;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtQuantity;
    private javax.swing.JTextField txtSName;
    private javax.swing.JTextField txtUsername;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the Id
     */
    public String getId() {
        return Id;
    }

    /**
     * @param Id the Id to set
     */
    public void setId(String Id) {
        this.Id = Id;
    }

    /**
     * @return the UserId
     */
    public String getUserId() {
        return UserId;
    }

    /**
     * @param UserId the UserId to set
     */
    public void setUserId(String UserId) {
        this.UserId = UserId;
    }

    /**
     * @return the CateId
     */
    public String getCateId() {
        return CateId;
    }

    /**
     * @param CateId the CateId to set
     */
    public void setCateId(String CateId) {
        this.CateId = CateId;
    }
    
    /**
     * @return the CusId
     */
    public String getCusId() {
        return CusId;
    }

    /**
     * @param aCusId the CusId to set
     */
    public void setCusId(String aCusId) {
        CusId = aCusId;
    }

    /**
     * @return the ItemId
     */
    public String getItemId() {
        return ItemId;
    }

    /**
     * @param ItemId the ItemId to set
     */
    public void setItemId(String ItemId) {
        this.ItemId = ItemId;
    }

    /**
     * @return the CusName
     */
    
    public String getCusName() {
        return CusName;
    }

    /**
     * @param aCusName the CusName to set
     */
    public void setCusName(String aCusName) {
        CusName = aCusName;
    }
}
